# -*- coding: utf-8 -*-
# 获取到市中心的距离和时间
import requests
import sys
import pymongo
import json

reload(sys)
sys.setdefaultencoding('utf-8')


connection = pymongo.MongoClient('139.224.135.121', 27017)
db = connection.lianjia
db.authenticate("developer","qwerqwer")
ershoufang = db.ShDeal
count = ershoufang.count()
k = 1000
while k < count :
    j=k
    cursor = ershoufang.find().limit(100).skip(k)
    for i in cursor:
        print i
        print j
        j = j + 1
        # try :
        #     distance = ''
        #     duration = ''
        #     originStr = i['lat'] + ',' + i['lng']
        #     r = requests.get('http://api.map.baidu.com/routematrix/v2/driving?output=json&origins='+originStr+'&destinations=31.237767,121.490602&ak=rEtXV0F4Uq6kEHDHDxP9I4hFmEYND0R0')
        #     print r.text;
        #     if r.text.find("成功") == -1 :
        #         continue
        #     else :
        #         t = json.loads(r.text)
        #         distance = t['result'][0]['distance']['value']
        #         duration = t['result'][0]['duration']['value']
        #     print j
        #     j = j + 1
        #     print i['_id']
        #     ershoufang.update({"_id":i['_id']},{"$set":{"distance":distance,"duration":duration}})
        # except :
        #     print "出了一点小问题"
    k = k + 100